<!--
 * @Author: liuyonghu
 * @Date: 2022-06-20 18:08:33
 * @LastEditTime: 2022-07-21 17:43:31
 * @LastEditors: liuyonghu
 * @Description: 
 * @FilePath: /demos/promise/面试题.html
-->

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    (async () => {
      console.log(0);

      setTimeout(() => {
        console.log(1);
      });

      const promise = new Promise((resolve, reject) => {
        console.log(2);
        const interval = setInterval(() => {
          console.log(3);
        }, 100);
        clearInterval(interval);
        resolve(4);
      })

      Promise.resolve(() => {
        console.log(5)
      })

      await promise.then((num) => {
        console.log('num - ',num);
      })

      console.log(6);
    })()
  </script>


  <script>

    // let then = {
    //   then: (resolve, reject) => {
    //     console.log(1)
    //     resolve(then)
    //   }
    // }

    // Promise.resolve(then) //这会造成一个死循环

  </script>
</body>

</html>